#include "MsgTalk.h"
#include "EventMgr.h"

namespace cupid
{
MsgTalk::MsgTalk()
{
	init();
	m_template	=(msg_talk *)m_bufMsg;

}

MsgTalk::~MsgTalk()
{

}

//////////////////////////////////////////////////////////////////////
BOOL MsgTalk::create(const char* szName, int tm, const char* data)
{
	// init
	this->init();

	// fill info now
	m_template->m_size	=sizeof(msg_talk);
	m_template->m_type	=msg_type_talk;

	m_template->m_time	= tm;
	strcpy_s(m_template->m_sname, szName);
	strcpy_s(m_template->m_data, data);

	return true;
}

//////////////////////////////////////////////////////////////////////
BOOL MsgTalk::create(char* bufMsg, DWORD dwMsgSize)
{
	if (!NetMsg::create(bufMsg, dwMsgSize))
		return false;

	if(msg_type_talk != this->getType())
		return false;

	return true;
}

//////////////////////////////////////////////////////////////////////
void MsgTalk::process(void* pInfo)
{
	MsgSn sn;
	sn << getSocketID();
	sn << string(m_template->m_sname);
	sn << string(m_template->m_data);
	sEventMgr->trigger(event_talk, &sn);
}
}